package com.heima.tess4j;

import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;

import java.io.File;

public class Main {
    public static void main(String[] args) {
        //获取本地图片
        File file = new File("e:/picture.png");
        //创建Tesseract对象
        Tesseract tesseract = new Tesseract();
        //设置字体库路径
        tesseract.setDatapath("e:/tessdata");
        //中文识别
        tesseract.setLanguage("chi_sim");
        //执行ocr识别
        try {
            String result = tesseract.doOCR(file);
            //替换回车和tal键使结果为一行
            result=result.replaceAll("\\r|\\n","-").replaceAll(" ","");
            System.out.println("结果为："+result);
        } catch (TesseractException e) {
            e.printStackTrace();
        }
    }
}
